package com.fengfeng.sdk;

import com.fengfeng.sdk.model.UserInfo;
import com.fengfeng.utils.FFDataUtils;
import com.google.gson.Gson;

/**
 * @author xiaoguokeng
 * 用于管理登录后的用户信息
 * @Date 2024/8/7
 */
public class UserCenterManager {

    private static UserCenterManager mInstance;

    private UserCenterManager() {
    }

    public static UserCenterManager getInstance() {
        if (mInstance == null) {
            mInstance = new UserCenterManager();
        }
        return mInstance;
    }

    public void saveUserData(UserInfo userInfo) {
        Gson gson = new Gson();
        String data = gson.toJson(userInfo);
        FFDataUtils.saveStringData(SDKConstants.USER_DATA, data);
    }

    public UserInfo getUserInfo() {
        String json = FFDataUtils.getStringData(SDKConstants.USER_DATA);
        if(json.isEmpty()){
            return null;
        }
        Gson gson = new Gson();
        UserInfo userInfo = gson.fromJson(json, UserInfo.class);
        if (userInfo != null) {
            return userInfo;
        }
        return null;
    }
}
